<!--
  功能：学生档案
  作者：licy
  邮箱：licy@briup.com
  时间：2020年12月07日 14:59:47
  版本：v1.0
  修改记录：
  修改内容：
  修改人员：
  修改时间：
-->
<template>
  <div class='student_list'>
    <!-- 按钮 -->
    <div class="btns">
      <div style="text-align:center;margin-bottom:.5em">
        <el-form size="small" :inline='true'>
          <el-form-item>
            <el-date-picker style="width:120px" v-model="param.year" value-format="yyyy" type="year" placeholder="毕业年份"> </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-cascader filterable v-model="param.channelIds" clearable :options="channels" placeholder="请选择渠道" :props="{ checkStrictly: true ,children:'children',label:'name',value:'id', emitPath: false,multiple:true}" ></el-cascader>
          </el-form-item>
          <el-form-item>
            <el-cascader filterable v-model="param.clazzId" clearable :options="directionClazzTree" placeholder="请选择班级"
          :props="{ children:'clazzes',label:'name',value:'id',emitPath: false}" ></el-cascader>
          </el-form-item>
          <el-form-item >
            <el-select v-model="param.status" placeholder="状态" style="width:120px" clearable>
              <el-option value="报名中" label="报名中"></el-option>
              <el-option value="待选方向" label="待选方向"></el-option>
              <el-option value="待分班" label="待分班"></el-option>
              <el-option value="学习中" label="学习中"></el-option>
            </el-select>  
          </el-form-item>
          <el-form-item >
            <el-input placeholder="姓名" v-model="param.realname" ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div style="text-align:right">
        <el-button size="small" type="primary" icon="el-icon-search" @click="toSearchHandler">搜索</el-button>
        <el-button size="small" icon="el-icon-upload" type="primary" @click="toStudentImportHandler">学生档案同步</el-button>
        <el-button type="primary" icon="el-icon-download" size="small" @click="toDownloadStudentHandler">导出</el-button>
      </div>
    </div>
    <!-- 按钮 -->
    <!-- 表格 -->
    <!-- @row-click="toStudentDetailsHandler" -->
     <el-table ref="multipleTable" :data="studentData.list" size="small" v-loading="loading"  
      :row-class-name="attentionStudentClass">
        <el-table-column type="index" :index="1" label="序号" align="center" fixed="left"/>
        <el-table-column prop="realname" label="姓名" width="90" align="center" fixed="left"/>
        <el-table-column prop="status" label="状态" width="80" align="center" fixed="left">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status ==='报名中'" type="danger" size="mini">{{scope.row.status}}</el-tag>
            <el-tag v-else-if="scope.row.status==='待分班'" type="warning" size="mini">{{scope.row.status}}</el-tag>
            <el-tag v-else-if="scope.row.status==='离校'" type="info" size="mini">{{scope.row.status}}</el-tag>
            <el-tag v-else type="success" size="mini">{{scope.row.status}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="谈话记录" align="center" width="300">
          <template slot-scope="scope">
            <div>
              <div v-if="scope.row.employeeEvents==0"><el-tag type="danger" size="mini">暂无谈话记录</el-tag></div>
              <div v-else>
                <div v-for="item in scope.row.employeeEvents" :key="item.id">
                  <div v-html="item.content"></div>
                </div>
              </div>  
            </div>
          </template>
        </el-table-column>
        <el-table-column label="考试记录" width="300">
          <template slot-scope="scope">
            <div>
              <div v-if="scope.row.studentExamExtends==0"><el-tag type="danger" size="mini">暂无考试记录</el-tag></div>
              <div v-else>
                <div v-for="item in scope.row.studentExamExtends" :key="item.id">
                  <div>{{item.examInfo?item.examInfo.name:''}} <el-tag>{{item.score}}</el-tag></div>
                </div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="学校" width="150" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.channel">
               {{scope.row.channel.parent?scope.row.channel.parent.name:""}}
            </div>
            <div v-else>
              暂无信息
            </div>
          </template>
        </el-table-column>
        <el-table-column label="学院" width="150" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.channel">
              {{scope.row.channel.name}}
            </div>
            <div v-else>
              暂无信息
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="major" label="专业" width="150" align="center"/>
        <el-table-column prop="schoolStuClazz" label="校内班级" width="200" align="center"/>
        <el-table-column prop="schoolStuNo" label="校内学号" width="150" align="center"/>
        <el-table-column prop="ddTel" label="钉钉手机号" width="140" align="center"/>
        <el-table-column prop="stuType" label="报名方式" width="80" align="center"/>
        <el-table-column prop="applyTime" label="报名时间" width="150" align="center">
          <template slot-scope="scope">
            {{scope.row.applyTime | fmtTime}}
          </template>
        </el-table-column>
        <el-table-column prop="idCard" label="身份证号" width="180" align="center"/>
        <el-table-column prop="gender" label="性别" width="60" align="center"/>
        <el-table-column prop="birth" label="出生日期" width="120" align="center">
          <template slot-scope="scope">
            {{scope.row.birth | fmtDate}}
          </template>
        </el-table-column>
        <el-table-column prop="education" label="学历" width="80" align="center"/>
        <el-table-column prop="graduationTime" label="毕业时间" width="120" align="center">
          <template slot-scope="scope">
            {{scope.row.graduationTime | fmtDate}}
          </template>
        </el-table-column>
        <el-table-column prop="flp" label="外语水平" width="80" align="center"/>
        <el-table-column prop="tel" label="手机号" width="120" align="center"/>
        <el-table-column prop="guardianTel" label="监护人手机号" width="120" align="center"/>
        <el-table-column prop="qq" label="qq号" width="120" align="center"/>
        <el-table-column prop="homeAddress" label="家庭住址" width="350" align="center"/>
        <el-table-column prop="isAttention" label="是否关注" width="120" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.isAttention" type="primary" size="small">{{scope.row.isAttention}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="籍贯" prop="nativePlace" width="200"></el-table-column>
        <el-table-column label="政治面貌" prop="politicsStatus" width="100"></el-table-column>
        
        <el-table-column label="操作" align="center" width="80" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click.stop="toEditStudent(scope.row)">修改</el-button>
          </template>
        </el-table-column>
      </el-table>
    <!-- /表格 -->
    <!-- 分页 -->
    <div class="page">
        <el-pagination background 
          layout="prev, pager, next,sizes,total" 
          small
          :total="studentData.total" 
          :page-size="studentData.pageSize" 
          :current-page="studentData.page"
          :page-sizes="[10, 15, 20,25,50,100]"
          @size-change="handleSizeChange"
          @current-change="currentChangeHandler">
        </el-pagination>
    </div>
    <!-- /分页 -->
    <!-- 模态框 -->
    <el-dialog title="导出配置" :visible.sync="dialog_visible" width="30%" class="customer_modal">
      <div style="text-align:center;padding:20px 0">
        <el-button size="small" @click="downloadHandler('current')">导出当前页</el-button>
        <el-button size="small" type="primary" @click="downloadHandler('all')">全部导出</el-button>
      </div>
    </el-dialog>
    <!-- /模态框 -->
    <!-- 抽屉 -->
    <Briupdrawer :drawer-visible="visible" :title="title" width="50%" @on-change-visible="handlerVisibleChange" >
      <div slot="content">
        <el-form ref="apply_form" :model="form" :rules="rules" size="mini" label-width="100px" label-position="center">
         
          <div class="sub_title">基本信息</div>
          <el-row>
            <el-col :span="12">
              <el-form-item label="姓名" prop="realname">
                <el-input v-model="form.realname"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="性别" prop="gender">
                <el-radio-group v-model="form.gender">
                  <el-radio label="男">男</el-radio>
                  <el-radio label="女">女</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="钉钉手机号" prop="ddTel">
                <el-input v-model="form.ddTel"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="手机号" prop="tel">
                <el-input v-model="form.tel"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="qq" prop="qq">
                <el-input v-model="form.qq"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="身份证号" prop="idCard">
                <el-input v-model="form.idCard"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="生日" prop="birth">
                <el-date-picker v-model="form.birth" value-format="timestamp" type="date" placeholder="选择日期" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="监护人" prop="guardian">
                <el-input v-model="form.guardian"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系方式" prop="guardianTel">
                <el-input v-model="form.guardianTel"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          
          <el-row>
            <el-col :span="24">
              <el-form-item label="地址" prop="address">
                <el-input v-model="form.homeAddress"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="sub_title">渠道信息</div>
          <el-form-item label="学校渠道" prop="channelId">
            <el-cascader filterable style="width:100%" v-model="form.channelId" clearable :options="channels" placeholder="请选择院校渠道"
        :props="{ children:'children',label:'name',value:'id', emitPath: false}" ></el-cascader>
          </el-form-item>

          <el-row>
            <el-col :span="12">
              <el-form-item label="校内班级" prop="schoolStuClazz">
                <el-input v-model="form.schoolStuClazz"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="校内学号" prop="schoolStuNo">
                <el-input v-model="form.schoolStuNo"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
               <el-form-item label="毕业时间" prop="graduationTime">
                <el-date-picker v-model="form.graduationTime" value-format="timestamp" type="date" placeholder="选择日期" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
               <el-form-item label="专业" prop="major">
                <el-input v-model="form.major"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="学历" prop="education">
                <el-select v-model="form.education">
                  <el-option label="大专" value="大专"></el-option>
                  <el-option label="本科" value="本科"></el-option>
                  <el-option label="研究生" value="研究生"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="外语水平" prop="flp">
                <el-select v-model="form.flp">
                  <el-option value="无" label="无"></el-option>
                  <el-option value="CET4" label="CET4"></el-option>
                  <el-option value="CET6" label="CET6"></el-option>
                  <el-option value="CET8" label="CET8"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
         
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="visible = false">取 消</el-button>
        <el-button type="primary" size="small" @click="submitHandler">确 定</el-button>
      </span>
    </Briupdrawer>
   


  </div>
</template>

<script>
import {get,post} from '@/utils/request'
import _ from 'lodash'
import { mapGetters } from 'vuex'
import qs from 'qs'
import Tinymce from '@/components/Tinymce'
import moment from 'moment'
export default {
  // 组件名称
  name: 'demo',
  // 组件参数 接收来自父组件的数据
  props: {},
  // 组件状态值
  data () {
   return {
     random:0,
     student:{},
     students:[],
     visible:false,
     dialog_visible:false,
     loading:false,
     title:"修改学员档案",
     param:{
       page:1,
       pageSize:15
     },
     form:{},
     rules: {
        ddTel: [ { required: true, message: '请输入钉钉手机号', trigger: 'blur' } ],
        tel: [ { required: true, message: '请输入手机号', trigger: 'blur' } ],
        realname: [ { required: true, message: '请输入姓名', trigger: 'blur' } ],
        qq: [ { required: true, message: '请输入qq', trigger: 'blur' } ],
        gender: [ { required: true, message: '请选择性别', trigger: 'blur' } ],
        idCard: [ { required: true, message: '请输入身份证号', trigger: 'blur' } ],
        birth: [ { required: true, message: '请输入生日', trigger: 'blur' } ],
        flp: [ { required: true, message: '请选择外语水平', trigger: 'change' } ],
        major: [ { required: true, message: '请输入专业', trigger: 'change' } ],
        channelId:[{ required: true, message: '请选择院校渠道', trigger: 'change' }],
        education:[{ required: true, message: '请选择学历', trigger: 'change' }],
        graduationTime:[{ required: true, message: '请选择毕业时间', trigger: 'change' }]
      },
    
     studentData:{list:[]},
   }
  },
  components: { Tinymce },
  // 计算属性
  computed: {
    ...mapGetters(['channels','directionClazzTree','user']),
  },
  // 侦听器
  watch: {
   'param.dc':{
     handler(now){
       this.param.directionId = now[0];
       this.param.clazzId = now[1];
     }
   }
  },
  // 组件方法
  methods: {
    toSearchHandler(){
      this.param.page = 1;
      this.loadStudents();
    },
     // 重点关注学生
    attentionStudentClass({row, rowIndex}){
      let flag = '';
      switch(row.isAttention){
        case '关系学生':
          flag = 'success-row'
          break;
        case '问题学生':
          flag = 'warning-row'
          break;
        default:
          flag = ''
      }
      return flag;
    },
    // 学生档案导入
    toStudentImportHandler(){
      this.$router.push({
        path:'/sms/employment/OldStudentImport'
      });
    },
     // 提交处理函数
    submitHandler() {
      this.$refs['apply_form'].validate((valid) => {
        if (valid) {
          const url = '/student/saveOrUpdate'
          post(url, this.form)
            .then(response => {
              this.visible = false
              this.$message({ message: response.message, type: 'success' })
              this.loadStudents()
            })
        } else {
          return false
        }
      })
    },
    // 去修改
    toEditStudent(row){
      this.form = _.clone(row);
      this.visible = true;
    },
    // 去下载学生档案信息
    toDownloadStudentHandler(){
       this.dialog_visible = true;
    },
     // 下载数据
    downloadHandler(type){
      // 去除空值
      let param = _.clone(this.param)
      for(let key in param){
        if(!param[key]){
          delete param[key]
        }
      }
      if(param.channelId){
        param.channelIds = [param.channelId]
      } else {
        delete param.channelIds;
      }
      switch(type){
        case "current":
          break;
        case "all":
          param.pageSize = 10000;
          break;
      }
      // window.location.href = "http://218.4.196.178:8008/studentEmployment/downloadStudentEmployment?"+qs.stringify(param,{ arrayFormat: 'repeat' });
      window.location.href = "http://218.4.196.178:8008/student/download?"+qs.stringify(param,{ arrayFormat: 'repeat' });
     // 关闭模态框
      this.dialog_visible = false;
    },
    //处理visible变化的钩子函数,解决抽屉无法收缩的bug
    handlerVisibleChange(val){
      this.visible = val;
    },
  
    // 加载学生信息
    loadStudents(){
      this.loading = true;
      let url = '/student/pageQuery'
      // 去除空值
      for(let key in this.param){
        if(!this.param[key]){
          delete this.param[key]
        }
      }
     
      get(url+"?"+qs.stringify(this.param,{ arrayFormat: 'repeat' }))
      .then(response => {
        this.studentData = response.data
        this.loading = false;
      })
    },
     // 当前页发生改变
    currentChangeHandler(page){
      this.param.page = page;
      this.loadStudents();
    },
     // 处理分页大小变化的函数
    handleSizeChange(pageSize){
      // 当前页为第一页
      this.page = 1;
      // 页面大小为用户选择的页面
      this.param.pageSize = pageSize;
      this.loadStudents();
    },
    
  },
  // 以下是生命周期钩子
  /**
  * 组件实例创建完成，属性已绑定，但DOM还未生成，$ el属性还不存在
  */
  created () {
    this.loadStudents();
  },
  /**
  * el 被新创建的 vm.$ el 替换，并挂载到实例上去之后调用该钩子。
  * 如果 root 实例挂载了一个文档内元素，当 mounted 被调用时 vm.$ el 也在文档内。
  */
  mounted () {
  },
  /**
  * 实例销毁之前调用。在这一步，实例仍然完全可用。
  */
  beforeDestroy () {
  },
  /**
  * Vue 实例销毁后调用。调用后，Vue 实例指示的所有东西都会解绑定，
  * 所有的事件监听器会被移除，所有的子实例也会被销毁。
  */
  destroyed () {
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<!--使用了scoped属性之后，父组件的style样式将不会渗透到子组件中，-->
<!--然而子组件的根节点元素会同时被设置了scoped的父css样式和设置了scoped的子css样式影响，-->
<!--这么设计的目的是父组件可以对子组件根元素进行布局。-->
<style scoped>

</style>
